﻿package Net::FTP::Client::Listing::System::Unix;

use JIP::ToolSet; # load my commonly-used modules in a single import
use parent qw( Net::FTP::Client::Listing );
use Readonly qw( Readonly );
use English qw( -no_match_vars );

Readonly my $REGEX => qr/^([d-])[a-z-]{9}     # drwxr-xr-x
                        \s+\d*                # 1
                        (?:\s+\w+){2}         # ftp ftp
                        \s+(\d+)              # 0
                        \s+\w+\s+\d+\s+[\d:]+ # Feb 15 17:34
                        \s+(.+)               # linux_format
                        $/x;

sub parseDir {
    my $self = shift;

    my @listing;

    foreach ( @ARG ) {
        if ( my( $type, $size, $name ) = $ARG =~ $REGEX ) {
            if ( $type eq '-' ) {
                $type = 'f'
            }
            elsif ( $type eq 'd' ) {
                $size = undef;

                next if $name eq '.' or $name eq '..';
            }

            push @listing, {
                name => $name,
                type => $type,
                size => $size
            };
        }
    }

    return @listing;
}

1;
